<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width" />
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" href="../css/mycollege.css">

</head>
<body>
    <div class="header">
      <h3>我的大学</h3>
    </div>

    <div class="person">
   <div class="personAlter">
     <div class="personHead">

     </div>
     <div class="alterHead">

     </div>
   </div>
   <div class="userName">
       <p>userName</p>
   </div>
 </div>

    <div id="footer">
      <div class = "footer footer1">
        <img src="../image/my.png" alt="" style="height:40px;">
        <span class="f1">职业能力标准</span>
        <div class="go"> </div>
      </div>
      <div class = "footer footer2">
        <img src="../image/yijian3.png" alt="" style="height:40px;">
        <span class="f1">意见反馈</span>
        <div class="go"> </div>
      </div>
      <div class = "footer footer3">
        <img src="../image/apply.png" alt="" style="height:40px;">
        <span class="f1">申请成为项目经理</span>
        <div class="go"> </div>
      </div>
      <div class = "footer footer4">
        <img src="../image/shezhi.png" alt="" style="height:40px;">
        <span class="f1">系统设置与说明</span>
        <div class="go"> </div>
      </div>
    </div>


</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="../script/main.js">

</script>
<script type="text/javascript">
apiready=function(){
  var aid=$api.getStorage('aid');
  //获取用户头像，昵称
  var headImagesUrl=$api.getStorage('userHeaderImageUrl');
  var nickname=$api.getStorage('nickname');
  $(".personHead").css("background-image","url("+headImagesUrl+")");
  $(".userName p").html(nickname);
//修改头像
$(".alterHead").click(function(){
    if($api.getStorage('aid') == 1){
      api.toast({
          msg: '此功能仅提供用户使用'
      });
    }
    else{
      api.actionSheet({
             title: '上传头像',
             cancelTitle: '取消',
             buttons: ['拍照', '从手机相册选择']
         }, function(ret, err) {

          var sourceType = 'album';

          if (3 == ret.buttonIndex) { // 取消
              return;
          }

          if (1 == ret.buttonIndex) { // 打开相机
              sourceType = 'camera';
          }

          api.getPicture({
              sourceType: sourceType,
              destinationType:'base64',

          }, function(ret, err) {
            if(err){
              alert('取消操作！');
            }else{
              if(ret.data.length){
                 var url='/api/paTechnicaluser/'+$api.getStorage("aid")+'/header';
                 var headImages=ret.base64Data.split(",")[1];
                 var functionRet=function(ret){
                    console.log(JSON.stringify(ret))
                 }
                 var functionErr=function(err){
                   if(err.statusCode==200){
                     api.alert({ msg: '头像修改成功！' });
                   }else{
                     toast("头像修改失败，请重试","bottom");
                   }
                 }
                 var jsons={
                    "headImages": ret.base64Data.split(",")[1],
                    "headImagesType": "jpg"
                 };
                 put(url,jsons,functionRet,functionErr);
                 $(".personHead").css("background-image","url("+ret.base64Data+")");
              }else{
                if(ret.data.length==0){
                  toast("取消修改头像","bottom");
                }else {
                  toast("上传头像失败！","bottom");
                }
              }
            }
          });
      });
    }
  })

// $(".alterHead").click(function(){
//   api.actionSheet({
//       title: '上传头像',
//       cancelTitle: '取消',
//       buttons: ['拍照','从手机相册选择']
//   }, function(ret, err) {
//       if (ret) {
//           getPicture(ret.buttonIndex);
//
//       }
//   });
// })
// function getPicture(sourceType) {
//     if(sourceType==1){ // 拍照
//         //获取一张图片
//         api.getPicture({
//             sourceType: 'camera',
//             encodingType: 'png',
//             mediaValue: 'pic',
//              destinationType: 'base64',
//             allowEdit: false,
//             quality: 90,
//             saveToPhotoAlbum: true
//         }, function(ret, err) {
//             // 获取拍照数据并处理
//             if (ret) {
//                 console.log(ret);
//                 console.log(JSON.stringify(ret));
//             }
//         });
//     }
//     else if(sourceType==2){ // 从相机中选择
//       var UIMediaScanner  = api.require('UIMediaScanner');
//
// UIMediaScanner.open({
//     type: 'picture',
//     column: 4,
//      destinationType: 'base64',
//     classify: true,
//     max: 1,
//
//     sort: {
//         key: 'time',
//         order: 'desc'
//     },
//     texts: {
//         stateText: '',
//         cancelText: '取消',
//         finishText: '完成'
//     },
//     styles: {
//         bg: '#fff',
//         mark: {
//             icon: '',
//             position: 'bottom_left',
//             size: 20
//         },
//         nav: {
//             bg: '#eee',
//             stateColor: '#000',
//             stateSize: 18,
//             cancelBg: 'rgba(0,0,0,0)',
//             cancelColor: '#000',
//             cancelSize: 18,
//             finishBg: 'rgba(0,0,0,0)',
//             finishColor: '#000',
//             finishSize: 18
//         }
//     },
//
//     exchange: true,
//     rotation: true,
//
//
// }, function(ret,err) {
//     if (ret) {
//       if(err){
//           console.log(rer);
//       }
//     }
// if(err){
//     console.log(err);
// }
//
// });
//     }
// }




  //导航栏菜单
var MNNavigationMenu = api.require('MNNavigationMenu');
MNNavigationMenu.open({
    rect: {
        x: 0,
        y: 205,
        w: api.winWidth,
        h: 56
    },
    index: 0,
    animation: true,
    styles: {
        column: 4,
      //   bg: 'red',
        item: {
             //bg: 'rgba(247,247,247,0.7)',
            title: {
                marginB: 6,
                size: 14,
                height: 14,
                color: '#8a8a8a',
                active: '#8a8a8a',
                // highlight: '#37acfe',
                ttf:'Alkatip Basma Tom'
            },
            icon: {
                marginT: 3,
                width: 32,
                height: 32,
                corner: 2
            }
        }
    },
    items: [{
        title: '个人信息',
        icon: 'widget://image/jianli.png',
        active: 'widget://image/jianli.png',
        highlight: 'widget://image/jianli.png'
    }, {
        title: '我的项目',
        icon: 'widget://image/toudi.png',
        active: 'widget://image/toudi.png',
        highlight: 'widget://image/toudi.png'
    },{
        title: '我的帖子',
        icon: 'widget://image/essay.png',
        active: 'widget://image/essay.png',
        highlight: 'widget://image/essay.png'
    }, {
        title: '我的关注',
        icon: 'widget://image/guanzhu.png',
        active: 'widget://image/guanzhu.png',
        highlight: 'widget://image/guanzhu.png'
    }],
    fixedOn: api.frameName,
    fixed: false
}, function(ret, err) {
    if(ret){
      if(ret.index==0){
        if(aid == 1){
          api.toast({
              msg: '此功能仅提供用户使用'
          });
        }
        else{
          openPage('personInformation','./college/personInformation.html');
        }
      }
      if(ret.index==1){
        openPage('send','./colleague/send.html');
      }
      if(ret.index==2){
        openPage('myArticle','forum/myArticle.html');
      }
      if(ret.index==3){
        //关注的帖子
        openPage('attentionArticle','forum/attentionArticle.html');
      }
    }
});}
</script>

</html>
